package com.anyou.mall.parts.controller;

import java.math.BigDecimal;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.anyou.common.core.domain.AjaxResult;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.anyou.common.annotation.Log;
import com.anyou.common.core.controller.BaseController;
import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.enums.BusinessType;
import com.anyou.mall.parts.domain.PlaPartsClassify;
import com.anyou.mall.parts.service.IPlaPartsClassifyService;
import com.anyou.common.utils.poi.ExcelUtil;

/**
 * 配件分类Controller
 * 商品分类
 * @author ylj
 * @date 2022-03-09
 */
@Api(tags = "商品分类")
@RestController
@RequestMapping("/parts/classify")
public class PlaPartsClassifyController extends BaseController
{
    @Autowired
    private IPlaPartsClassifyService plaPartsClassifyService;

    /**
     * 查询配件分类列表
     */
    @ApiOperation("查询商品分类列表")
    @PreAuthorize("@ss.hasPermi('parts:classify:list')")
    @GetMapping("/list")
    public AjaxResult list(PlaPartsClassify plaPartsClassify)
    {
        List<PlaPartsClassify> list = plaPartsClassifyService.selectPlaPartsClassifyList(plaPartsClassify);
        return AjaxResult.success(list);
    }

    /**
     * 导出配件分类列表
     */
    @ApiOperation("导出商品分类列表")
    @PreAuthorize("@ss.hasPermi('parts:classify:export')")
    @Log(title = "配件分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlaPartsClassify plaPartsClassify)
    {
        List<PlaPartsClassify> list = plaPartsClassifyService.selectPlaPartsClassifyList(plaPartsClassify);
        ExcelUtil<PlaPartsClassify> util = new ExcelUtil<PlaPartsClassify>(PlaPartsClassify.class);
        util.exportExcel(response, list, "配件分类数据");
    }

    /**
     * 获取配件分类详细信息
     */
    @ApiOperation("获取商品分类详细信息")
    @PreAuthorize("@ss.hasPermi('parts:classify:query')")
    @GetMapping(value = "/{partsClassifyId}")
    public ApiResult<PlaPartsClassify> getInfo(@PathVariable("partsClassifyId") Long partsClassifyId)
    {
        return ApiResult.success(plaPartsClassifyService.selectPlaPartsClassifyByPartsClassifyId(partsClassifyId));
    }

    /**
     * 新增配件分类
     */
    @ApiOperation("新增商品分类")
    @PreAuthorize("@ss.hasPermi('parts:classify:add')")
    @Log(title = "配件分类", businessType = BusinessType.INSERT)
    @PostMapping
    public ApiResult add(@RequestBody PlaPartsClassify plaPartsClassify)
    {
        return ApiResult.success(plaPartsClassifyService.insertPlaPartsClassify(plaPartsClassify));
    }

    /**
     * 修改配件分类
     */
    @ApiOperation("修改商品分类")
    @PreAuthorize("@ss.hasPermi('parts:classify:edit')")
    @Log(title = "配件分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public ApiResult edit(@RequestBody PlaPartsClassify plaPartsClassify)
    {
        return ApiResult.success(plaPartsClassifyService.updatePlaPartsClassify(plaPartsClassify));
    }

    /**
     * 删除配件分类
     */
    @ApiOperation("删除商品分类")
    @PreAuthorize("@ss.hasPermi('parts:classify:remove')")
    @Log(title = "配件分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{partsClassifyIds}")
    public ApiResult remove(@PathVariable Long[] partsClassifyIds)
    {
        return ApiResult.success(plaPartsClassifyService.deletePlaPartsClassifyByPartsClassifyIds(partsClassifyIds));
    }

    /*@ApiOperation("查看绑定的固定参数")
    @PreAuthorize("@ss.hasPermi('parts:classify:query')")
    @PostMapping(value = "/getParam")
    public ApiResult getParam(@RequestParam(value = "partsClassifyId") Long partsClassifyId)
    {
        return plaPartsClassifyService.getParam(partsClassifyId);
    }*/

    /*@ApiOperation("绑定固定参数")
    @PreAuthorize("@ss.hasPermi('parts:classify:bindingParam')")
    @PostMapping(value = "/bindingParam")
    public ApiResult bindingParam(@RequestParam(value = "partsClassifyId") Long partsClassifyId, @RequestParam(value = "paramList") @ApiParam(value = "参数名称列表") List<String> paramList)
    {
        return plaPartsClassifyService.bindingParam(partsClassifyId,paramList);
    }*/

    @ApiOperation("首页显示")
    @Log(title = "商品分类", businessType = BusinessType.UPDATE)
    @PostMapping("/changeIsShow")
    public ApiResult changeIsShow(@RequestParam Long partsClassifyId , @RequestParam String isShow)
    {
        return plaPartsClassifyService.changeIsShow(partsClassifyId,isShow);
    }

    /*@ApiOperation("查看配送费一口价")
    @PreAuthorize("@ss.hasPermi('parts:classify:query')")
    @PostMapping(value = "/getFee")
    public ApiResult getFee(@RequestParam(value = "partsClassifyId") Long partsClassifyId)
    {
        return plaPartsClassifyService.getFee(partsClassifyId);
    }*/

    /*@ApiOperation("设置配送费一口价")
    @PreAuthorize("@ss.hasPermi('parts:classify:bindingParam')")
    @PostMapping(value = "/setFee")
    public ApiResult setFee(@RequestParam(value = "partsClassifyId") Long partsClassifyId, @RequestParam(value = "price") BigDecimal price)
    {
        return plaPartsClassifyService.setFee(partsClassifyId,price);
    }*/
}
